# 多阶构建for docker-compose
FROM node:12-alpine as builder
ENV VERSION 1.10.2
ENV GIT_MIRROR_URL https://gitee.com/mirrors/YApi.git
WORKDIR /yapi
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk add --no-cache python2 make git
RUN git clone -b v${VERSION} --depth=1 ${GIT_MIRROR_URL} vendors
RUN cd /yapi/vendors && rm -rf package-lock.json && cp config_example.json ../config.json && npm install --production --registry https://registry.npm.taobao.org

FROM node:12-alpine
MAINTAINER pk<pinkersu@gmail.com>
ENV TZ="Asia/Shanghai"
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk add --no-cache bash
COPY --from=builder /yapi/vendors /yapi/vendors
WORKDIR /yapi/vendors
COPY wait-for-it.sh /
COPY start.sh /bin
RUN chmod +x /bin/start.sh && chmod +x /wait-for-it.sh
EXPOSE 3000
ENTRYPOINT ["start.sh"]
